﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;

namespace BLL
{
    public class WardBLL
    {
        HospitalDataContext DB = new HospitalDataContext();
        public IQueryable SelectWardChargeNurse()
        {
            return DB.Staffs.Join(
                DB.Jobs,
                a => a.StaffID,
                b => b.StaffID,
                (a, b) => new
                {
                    Name = a.FirstName + " " + a.LastName,
                    b.PositionID,
                    b.FinishDate,
                    b.JobID
                }
                ).Where(s => s.FinishDate == null).Join(
                DB.Positions,
                c => c.PositionID,
                d => d.PositionID,
                (c, d) => new
                {
                    c.Name,
                    d.Position1,
                    c.JobID

                }
                ).Where(s => s.Position1 == "Charge Nurse").Join(
                    DB.StaffOfWards,
                    g => g.JobID,
                    h => h.JobID,
                    (g, h) => new
                    {
                        g.Name,
                        h.WardID

                    }
                ).Join(
                DB.Wards,
                e => e.WardID,
                f => f.WardID,
                (e, f) => new
                {
                    e.Name,
                    f.WardID,
                    f.WardName,
                    f.Location,
                    f.TelExtn
                }
                ).Distinct().AsQueryable();

        }
        public IQueryable SelectAllWard()
        {
            return DB.Wards.AsQueryable();
        }
    }
}
